goog.provide('czk.ui.Input');

goog.require('goog.dom');
goog.require('goog.dom.TagName');

goog.require('czk.ui.ZKComponent');

/**
 * @constructor
 * @extends {czk.ui.ZKComponent}
 */
czk.ui.Input = function() {
  goog.base(this);
};
goog.inherits(czk.ui.Input, czk.ui.ZKComponent);

czk.ui.Input.prototype.initialize = function(name, parameter, portlet, children) {
  goog.base(this, 'initialize', name, parameter, portlet, children);
};

czk.ui.Input.prototype.createDom = function() {
  var dh = this.getDomHelper();
  var el = dh.createDom(goog.dom.TagName.INPUT, {
    'className': this.className,
    'value': this.value,
    'type': 'text'
  });

  this.setElementInternal(el);
};

/** @inheritDoc */
czk.ui.Input.prototype.enterDocument =
    function() {
      goog.base(this, 'enterDocument');
      this.getHandler().listen(this.getElement(),
          goog.ui.Component.EventType.CHANGE, this.change, false, this);

    };

czk.ui.Input.prototype.change = function() {
  var data = '{"value":"' + this.getElement()['value'] + '"}';
  this.portlet.sendXhr(this, 'onChange', data);

};

czk.ui.Input.prototype.handleZKResponseCommand = function(command) {
  goog.base(this, 'handleZKResponseCommand', command);
  this.getElement()['value'] = this.value;
};

czk.ui.Input.create = function() {
  return new czk.ui.Input();  
};
